 
						** VT analysing core 4 ***
	clear
	version 15.1
	set seed 1234 
 	cd ""

								*** COMP ***
	clear 
	use "core_comp.dta"
	
	** dropping unnecessary variables **
		
			drop if _id==.
		*	drop title marginsok vce depvar cmd properties predict model ///
		*		estat_cmd vcetype clustvar 
		drop cmdline cmd model absvar depvar  ///
 vcetype clustvar

		*	drop if vif1>7
		
		** 1.3. Mean of Coef, SE, min, max    **		 
			sum coef if var=="comp"
		** 1.4.  %(significant != 0)  **
			count if var=="comp" &   pval<=.05 & pval~=.	 	
		** 1.5. %(beta < 0)  		 
			count if var=="comp" & coef<0 & coef~=.
		** 1.5. %(beta > 0)  		 
			count if var=="comp" & coef>0 & coef~=.				
		** 1.6.  %(signif & beta <= 0)  				
			count if var=="comp" &  	pval<=.05 &	coef<=0 		
		** 1.7.  %(signif & beta > 0)  				
			count if var=="comp" &  	pval<=.05 &	coef>0 
		
		** Hegre and Sambanis weights calculation **	
		 
			** generating weights 
			egen llsum_all= sum(ll)
			gen w_all=ll/llsum_all
			
			* beta *
			gen beta_w=coef*w_all if var=="comp"
			egen beta_mean=sum(beta_w)		
			codebook beta_mean
			
			* sd *
			gen sd_w=stderr*w_all if var=="comp"
			egen sd_mean=sum(sd_w)
			codebook sd_mean
			
			* Tstat  *
			gen t=beta_mean/sd_mean
			codebook  t
			
			** Pvalue  (ttail(DF, T)
			display ttail( 1038960 ,  1.8456692  ) 
			                     
 
		** Sala-i-Martin's Extreme Bounds Analysis (EBA):
		
		sort coef
 		cumul coef if var=="comp", gen(cdf) equal
 		cumul beta_mean if var=="comp", gen(cdf_w) equal
				
		sort beta_mean
		browse coef cdf cdf_w if cdf~=.	
 		
		global graph_options ", freq  xline(0, lcolor(red)) ytitle("") xtitle("") normal gap(25) ylabel(, angle(0) labsize(small))"
		
		hist coef if var=="comp" $graph_options  title("Compulsory voting, Coefficients") saving(h2c, replace)
		hist tstat if var=="comp" $graph_options title("Compulsory voting, T-statistic") saving(h2t, replace)
		

								*** PR ***
	clear
  
		use "core_pr.dta"
	
	** dropping unnecessary variables **
		
			drop if _id==.
		*	drop title marginsok vce depvar cmd properties predict model ///
		*		estat_cmd vcetype clustvar 
		*	drop if vif1>7
			drop cmdline cmd model absvar depvar  ///
 vcetype clustvar

		** 1.3. Mean of Coef, SE, min, max    **		 
			sum coef if var=="pr"
		** 1.4.  %(significant != 0)  **
			count if var=="pr" &   pval<=.05 & pval~=.	 	
		** 1.5. %(beta < 0)  		 
			count if var=="pr" & coef<0 & coef~=.
		** 1.5. %(beta > 0)  		 
			count if var=="pr" & coef>0 & coef~=.				
		** 1.6.  %(signif & beta <= 0)  				
			count if var=="pr" &  	pval<=.05 &	coef<=0 		
		** 1.7.  %(signif & beta > 0)  				
			count if var=="pr" &  	pval<=.05 &	coef>0 
		
		** Hegre and Sambanis weights calculation **	
		  
		*drop llsum_all w_all beta_mean beta_w sd_w sd_mean t cdf cdf_w
			** generating weights 
			egen llsum_all= sum(ll)
			gen w_all=ll/llsum_all
			
			* beta *
			gen beta_w=coef*w_all if var=="pr"
			egen beta_mean=sum(beta_w)		
			codebook beta_mean
			
			* sd *
			gen sd_w=stderr*w_all if var=="pr"
			egen sd_mean=sum(sd_w)
			codebook sd_mean
			
			* Tstat  *
			gen t=beta_mean/sd_mean
			codebook  t
			
			** Pvalue  (ttail(DF, T)
			display ttail(1128376 ,1.7529062) 
			                     
 
		** Sala-i-Martin's Extreme Bounds Analysis (EBA):
		
		sort coef
 		cumul coef if var=="pr", gen(cdf) equal
 		cumul beta_mean if var=="pr", gen(cdf_w) equal
				
		sort beta_mean
		browse coef cdf cdf_w if cdf~=.	
 
		hist coef if var=="pr" $graph_options title("Proportional representation, Coefficients") saving(h3c, replace)
		hist tstat if var=="pr" $graph_options title("Proportional representation, T-statistic") saving(h3t, replace)
	
				

								*** GNI ***
	clear
 
		use "core_gni_ln_sl.dta"
	
	
	** dropping unnecessary variables **
		
			drop if _id==.
		*	drop title marginsok vce depvar cmd properties predict model ///
		*		estat_cmd vcetype clustvar 
		*	drop if vif1>7
			drop cmdline cmd model absvar depvar  ///
 vcetype clustvar

		** 1.3. Mean of Coef, SE, min, max    **		 
			sum coef if var=="gni_ln_sl"
		** 1.4.  %(significant != 0)  **
			count if var=="gni_ln_sl" &   pval<=.05 & pval~=.	 	
		** 1.5. %(beta < 0)  		 
			count if var=="gni_ln_sl" & coef<0 & coef~=.
		** 1.5. %(beta > 0)  		 
			count if var=="gni_ln_sl" & coef>0 & coef~=.				
		** 1.6.  %(signif & beta <= 0)  				
			count if var=="gni_ln_sl" &  	pval<=.05 &	coef<=0 		
		** 1.7.  %(signif & beta > 0)  				
			count if var=="gni_ln_sl" &  	pval<=.05 &	coef>0 
		
		** Hegre and Sambanis weights calculation **	
		  
		*drop llsum_all w_all beta_mean beta_w sd_w sd_mean t cdf cdf_w
			** generating weights 
			egen llsum_all= sum(ll)
			gen w_all=ll/llsum_all
			
			* beta *
			gen beta_w=coef*w_all if var=="gni_ln_sl"
			egen beta_mean=sum(beta_w)		
			codebook beta_mean
			
			* sd *
			gen sd_w=stderr*w_all if var=="gni_ln_sl"
			egen sd_mean=sum(sd_w)
			codebook sd_mean
			
			* Tstat  *
			gen t=beta_mean/sd_mean
			codebook  t
			
			** Pvalue  (ttail(DF, T)
			display ttail( 1171092 ,  -1.6774986) 
			                     
 
		** Sala-i-Martin's Extreme Bounds Analysis (EBA):
		
		sort coef
 		cumul coef if var=="gni_ln_sl", gen(cdf) equal
 		cumul beta_mean if var=="gni_ln_sl", gen(cdf_w) equal
				
		sort beta_mean
		browse coef cdf cdf_w if cdf~=.	
 
		hist coef if var=="gni_ln_sl" $graph_options title("GNI, Coefficients") saving(h4c, replace)
		hist coef if var=="gni_ln_sl" $graph_options title("GNI, T-statistics") saving(h4t, replace)
		

								*** POP ***
	clear 
		use "core_pop_ln_sl.dta"
		
	
	** dropping unnecessary variables **
		
			drop if _id==.
*			drop title marginsok vce depvar cmd properties predict model ///
*				estat_cmd vcetype clustvar 
*			drop if vif1>7
	drop cmdline cmd model absvar depvar  ///
 vcetype clustvar
		
		** 1.3. Mean of Coef, SE, min, max    **		 
			sum coef if var=="pop_ln_sl"
		** 1.4.  %(significant != 0)  **
			count if var=="pop_ln_sl" &   pval<=.05 & pval~=.	 	
		** 1.5. %(beta < 0)  		 
			count if var=="pop_ln_sl" & coef<0 & coef~=.
		** 1.5. %(beta > 0)  		 
			count if var=="pop_ln_sl" & coef>0 & coef~=.				
		** 1.6.  %(signif & beta <= 0)  				
			count if var=="pop_ln_sl" &  	pval<=.05 &	coef<=0 		
		** 1.7.  %(signif & beta > 0)  				
			count if var=="pop_ln_sl" &  	pval<=.05 &	coef>0 
		
		** Hegre and Sambanis weights calculation **	
		  
		*drop llsum_all w_all beta_mean beta_w sd_w sd_mean t cdf cdf_w
			** generating weights 
			egen llsum_all= sum(ll)
			gen w_all=ll/llsum_all
			
			* beta *
			gen beta_w=coef*w_all if var=="pop_ln_sl"
			egen beta_mean=sum(beta_w)		
			codebook beta_mean
			
			* sd *
			gen sd_w=stderr*w_all if var=="pop_ln_sl"
			egen sd_mean=sum(sd_w)
			codebook sd_mean
			
			* Tstat  *
			gen t=beta_mean/sd_mean
			codebook  t
			
			** Pvalue  (ttail(DF, T)
			display ttail(1170676,  .44282487) 
			                     
 
		** Sala-i-Martin's Extreme Bounds Analysis (EBA):
		
		sort coef
 		cumul coef if var=="pop_ln_sl", gen(cdf) equal
 		cumul beta_mean if var=="pop_ln_sl", gen(cdf_w) equal
				
		sort beta_mean
		browse coef cdf cdf_w if cdf~=.	
 
		hist coef if var=="pop_ln_sl" $graph_options title("Population, Coefficients") saving(h5c, replace)
		hist coef if var=="pop_ln_sl" $graph_options title("Population, T-statistic") saving(h5t, replace)
		
		 graph combine  h2c.gph h2t.gph h3c.gph h3t.gph h4c.gph ///
						h4t.gph h5c.gph h5t.gph , title("VAPVT: Core 5")	///
						
						saving(VAPVT_core.gph, replace)
 		 
		erase  core_pop_ln_sl.dta
		erase  core_gni_ln_sl.dta
		erase core_vapvt_lag.dta 
		erase core_comp.dta
		erase  core_pr.dta
